package com.example.jiwhsgs

import android.app.AlertDialog
import android.content.Intent
import android.database.sqlite.SQLiteDatabase
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.example.jiwhsgs.XSactivity.XSData
import java.io.IOException


class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        //导入数据库到创建的文件中
        val myHelper = MyDatabaseHelper(this)
        try {
            myHelper.CopyDBFile()
        } catch (e: IOException) {
            e.printStackTrace()
        }
    }

    fun onButtonGGClick(view: View) {
        // 在这里编写按钮点击事件的逻辑
        Toast.makeText(this, "zhangrang！", Toast.LENGTH_SHORT).show()
    }

    fun onButtoncalSPClick(view: View) {
        val intent = Intent(
            this,
            cal_sp::class.java
        )
        startActivity(intent)
    }

    fun onButtonXRClick(view: View) {
        // 获取字符串数组资源
        val XR = resources.getStringArray(R.array.xr_effects)
        //生成随机数0~2
        val randomIndex = (0..2).random()

        val builder = AlertDialog.Builder(this)
        builder.setTitle("效果")

        builder.setMessage(XR[randomIndex])
        builder.setPositiveButton("确定") { dialog, _ ->
            dialog.dismiss()
        }

        val dialog = builder.create()
        dialog.show()
    }

    fun onButtonLJClick(view: View) {
        val randomIndex = (0..3).random();
        val builder = AlertDialog.Builder(this)
        builder.setTitle("效果")
        if (randomIndex == 0) {
            builder.setMessage("造成伤害： 0");
        } else if (randomIndex == 1 || randomIndex == 2) {
            builder.setMessage("造成伤害： 1");
        } else if (randomIndex == 3) {
            builder.setMessage("造成伤害： 2");
        }
        builder.setPositiveButton("确定") { dialog, _ ->
            dialog.dismiss()
        }
        val dialog = builder.create()
        dialog.show()
    }

    fun onButtonLTClick(view: View) {
        val intent = Intent(
            this,
            LTactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonZXClick(view: View) {
        val intent = Intent(
            this,
            ZXactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonZQClick(view: View) {
        val intent = Intent(
            this,
            ZQactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonZCClick(view: View) {
        val intent = Intent(
            this,
            ZCactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonXSClick(view: View) {
        val intent = Intent(
            this,
            XSactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonSMSClick(view: View) {
        val intent = Intent(
            this,
            SMSactivity::class.java
        )
        startActivity(intent)
    }

    fun onButtonjiwhClick(view: View) {
        val intent = Intent(
            this,
            Jiwhactivity::class.java
        )
        startActivity(intent)
    }
}